package me.minecraft.plugin.playerride.command;

import me.minecraft.plugin.playerride.manager.MainManager;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * @author langle__
 * @version 1.0
 */
public class SelectCommand extends SubCommand {

    @Override
    public @NotNull String getName() {
        return "select";
    }

    @Override
    public @Nullable String getPermission() {
        return "PlayerRide.command.select";
    }

    @Override
    public void onCommand(Player player, String[] args) {
        Player target = player;
        if (args.length == 1) {
            if (!player.hasPermission("PlayerRide.command.select.other")) {
                player.sendMessage("[§c玩家骑乘§f] 你没有权限设置他人骑乘别人");
                return;
            }
            target = player.getServer().getPlayer(args[0]);
            if (target == null) {
                player.sendMessage("[§c玩家骑乘§f] 玩家 " + args[0] + " 不在线");
                return;
            }
        }
        if (MainManager.INSTANCE.hasRiderTarget(player)) {
            MainManager.INSTANCE.removeRiderTarget(player);
            player.sendMessage("[§a玩家骑乘§f] 取消选择状态");
        } else {
            MainManager.INSTANCE.setRiderTarget(player, target);
            player.sendMessage("[§a玩家骑乘§f] 选择一名玩家进行骑乘");
        }
    }

    @Override
    public List<String> onTabComplete(CommandSender sender, String[] args) {
        return null;
    }

}
